package xyz.renyumeng.xkm.shop.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.BooleanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import xyz.renyumeng.xkm.dto.shop.ProductTypeDto;
import xyz.renyumeng.xkm.exception.XkmException;
import xyz.renyumeng.xkm.model.shop.ProductTypeInfo;
import xyz.renyumeng.xkm.result.Result;
import xyz.renyumeng.xkm.shop.service.ProductTypeInfoService;

import javax.annotation.Resource;

/**
 * @author renyumeng
 * @date Created in 14:46 2023/7/1
 */

@RestController
@Api(tags = "管理员商品类型接口")
@RequestMapping("/admin/shop/type")
public class AdminProductTypeController {

    @Resource
    private ProductTypeInfoService productTypeInfoService;

    @DeleteMapping("/{typeId}")
    @ApiOperation(value = "根据id删除一个类别")
    public Result<Boolean> deleteTypeById(@PathVariable Long typeId) {
        return productTypeInfoService.deleteTypeByIdWithProduct(typeId);
    }

    @PutMapping
    @ApiOperation(value = "修改一个类型")
    public Result<Boolean> updateTypeById(@RequestBody ProductTypeDto productTypeDto) {
        return productTypeInfoService.updateTypeByIdWithProduct(productTypeDto);
    }

    @PostMapping
    @ApiOperation("增加一个类型")
    public Result<Boolean> addType(@RequestBody ProductTypeDto productTypeDto){
        return productTypeInfoService.addType(productTypeDto);
    }

    @GetMapping("/inner/{id}")
    public ProductTypeInfo innerGetTypeById(@PathVariable Long id) {
        return productTypeInfoService.getById(id);
    }
}
